package com.yanqu.road.server.cmd.activity.peakstronghold;

import com.yanqu.road.entity.activity.peakstronghold.config.PeakStrongHoldConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakStrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.peakstronghold.PeakStrongholdActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_PEAK_STRONGHOLD_MEMBER_DONATE_EXP_LIST, desc = "查看商会成员捐献经验")
public class PeakStrongholdMemberDonateExpListCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PeakStrongHoldConfig config = PeakStrongholdActivityMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

        PeakStrongholdWarProto.PeakStrongholdUnionMemberDonateExpListReqMsg reqMsg = PeakStrongholdWarProto.PeakStrongholdUnionMemberDonateExpListReqMsg.parseFrom(packet.getBytes());
        String unionUid = reqMsg.getUnionId();

        PeakStrongholdWarProto.CrossPeakHoldMemberDonateDetailReqMsg.Builder crossMsg = PeakStrongholdWarProto.CrossPeakHoldMemberDonateDetailReqMsg.newBuilder();
        crossMsg.setActivityId(config.getActivityInfo().getActivityId());
        crossMsg.setUnionId(unionUid);
        player.sendUnionActivityGroupPacket(Protocol.C_PEAK_STRONGHOLD_MEMBER_DONATE_EXP_LIST, crossMsg, crossMsg.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.S_PEAK_STRONGHOLD_MEMBER_DONATE_EXP_LIST, PeakStrongholdWarProto.PeakStrongholdUnionMemberDonateExpListRespMsg.newBuilder().setRet(ret));
        }
    }
}
